using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Serialization;
using UnityEngine.UI;

public class ChatSample : SingletonPatternMonoBase<ChatSample>
{
    /// <summary>
    /// 聊天配置
    /// </summary>
    [SerializeField] public ChatSetting m_ChatSettings;


    private void Awake()
    {
        InputSettingWhenWebgl();
    }

    #region 消息发送

    /// <summary>
    /// webgl时处理，支持中文输入
    /// </summary>
    private void InputSettingWhenWebgl()
    {
#if UNITY_WEBGL
        m_InputWord.gameObject.AddComponent<WebGLSupport.WebGLInput>();
#endif
    }




    #endregion

    #region 语音输入
   

    /// <summary>
    /// 语音输入处理类
    /// </summary>
    [SerializeField] private VoiceInputs m_VoiceInputs;
    /// <summary>
    /// 注册按钮事件
    /// </summary>


    /// <summary>
    /// 开始录制
    /// </summary>
    public void StartRecord()
    {
        m_VoiceInputs.StartRecordAudio();

        Debug.Log("Untone开始记录");

    }
    /// <summary>
    /// 结束录制
    /// </summary>
    public void StopRecord()
    {

        Debug.Log("Untone记录结束");
        m_VoiceInputs.StopRecordAudio(AcceptClip);



    }

    /// <summary>
    /// 处理录制的音频数据
    /// </summary>
    /// <param name="_data"></param>
    private void AcceptData(byte[] _data)
    {
        if (m_ChatSettings.m_SpeechToText == null)
            return;

        m_ChatSettings.m_SpeechToText.SpeechToText(_data, DealingTextCallback);
    }

    /// <summary>
    /// 处理录制的音频数据
    /// </summary>
    /// <param name="_data"></param>
    private void AcceptClip(AudioClip _audioClip)
    {
        if (m_ChatSettings.m_SpeechToText == null)
            return;

        m_ChatSettings.m_SpeechToText.SpeechToText(_audioClip, DealingTextCallback);

    }

    private void DealingTextCallback(string _msg)
    {
       

    }
    #endregion
}
